package com.rlz.aspectj;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;

import com.rlz.aspectj.common.Interceptor;
import com.rlz.aspectj.util.PermissionUtils;

import java.lang.ref.WeakReference;

public class AppInterceptor {

    private static Interceptor mInterceptor;

    private static WeakReference<Context> mContextWeakReference;

    private static PermissionUtils.OnPermissionDeniedListener sOnPermissionDeniedListener;


    public static void init(Application app) {
        mContextWeakReference = new WeakReference<>(app.getApplicationContext());
    }

    public static Context getContext() {
        return mContextWeakReference.get();
    }

    public static Interceptor getInterceptor() {
        return mInterceptor;
    }

    public static void setInterceptor(@NonNull Interceptor interceptor) {
        mInterceptor = interceptor;
    }


    /**
     * 设置权限申请被拒绝的监听
     */
    public static void setOnPermissionDeniedListener(@NonNull PermissionUtils.OnPermissionDeniedListener listener) {
        sOnPermissionDeniedListener = listener;
    }

    public static PermissionUtils.OnPermissionDeniedListener getOnPermissionDeniedListener() {
        return sOnPermissionDeniedListener;
    }
}
